package com.example.service.impl;

import com.example.mapper.oilChecklistMapp;
import com.example.pojo.oilChecklistPojo;
import com.example.service.oilChecklistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * ClassName:oilChecklistImpl
 * Package:com.example.service.impl
 * Description:
 *
 * @Author：牧星苑
 * @Create 2025/9/24 14:08
 * @Version 1.0
 */
@Service
public class oilChecklistImpl implements oilChecklistService {
    @Autowired
    private oilChecklistMapp oilChecklistMapp;
    @Override
    //一次插入多行点检结果
    public void insertSeveralRows(List<oilChecklistPojo> pojoList){
        for (int i = 0; i < pojoList.size(); i++) {
            //设置创立时间
            pojoList.get(i).setUpdate_time(LocalDateTime.now());
            pojoList.get(i).setCreate_time(LocalDateTime.now());
        }
        oilChecklistMapp.insertSeveralRows(pojoList);
    }

    //根据分页查询油液历史点检数据
    public List<oilChecklistPojo> queryByPage(Map<String, Object> map){
        Integer page =(Integer) map.get("page");
        Integer size=(Integer) map.get("size");
        String workshop=(String) map.get("workshop");
        Integer startRow=page*size;
        List<oilChecklistPojo> oilChecklistPojos=oilChecklistMapp.queryByPage(startRow, size, workshop);
        return oilChecklistPojos;
    }

    //查询所有油液历史点检数据条数
    public Integer queryQuantity(Map<String,Object> map){
        String workshop=(String) map.get("workshop");
        Integer quantity= oilChecklistMapp.queryQuantity(workshop);
        return quantity;
    }

    //修改一行油液点检信息
    public void editOneById(oilChecklistPojo pojo){
        pojo.setUpdate_time(LocalDateTime.now());
        oilChecklistMapp.editOneById(pojo);
    }

    //根据点检项目查询指定数量的数据
    public List<oilChecklistPojo> queryByOneField(Map<String, Object> map){
        Integer quantity = (Integer) map.get("quantity");
        String oil_basic_information_id = map.get("oil_basic_information_id").toString();
        List<oilChecklistPojo> pojoList = oilChecklistMapp.queryByOneField(quantity, oil_basic_information_id);
        return pojoList;
    }

    // 根据动态条件分页查询油液历史点检数据
    public List<oilChecklistPojo> queryByDynamicConditionsWithPagination(Map<String, Object> map) {
        // 获取分页参数
        Integer page = (Integer) map.get("page");
        Integer size = (Integer) map.get("size");

        // 设置默认值
        if (page == null) page = 0;
        if (size == null) size = 10;

        // 计算起始行
        Integer startRow = page * size;
        map.put("startRow", startRow);
        map.put("size", size);

        return oilChecklistMapp.queryByDynamicConditionsWithPagination(map);
    }
    // 根据动态条件查询油液历史点检数据总条数
    public Integer queryByDynamicConditionsCount(Map<String, Object> map) {
        return oilChecklistMapp.queryByDynamicConditionsCount(map);
    }

    //查询所有油液历史点检数据
    public List<oilChecklistPojo> queryAll(){
        List<oilChecklistPojo> pojoList=oilChecklistMapp.queryAll();
        return pojoList;
    }
}

